using System;
using Roslyn.Compilers.CSharp;

namespace BITS.PreCompiler.CSharp.Syntax.Extensions
{
    /// <summary>
    /// Extension methods for method nodes.
    /// </summary>
    public static partial class MethodExtension
    {
        /// <summary>
        /// Determines whether [is method return void] [the specified method node].
        /// </summary>
        /// <param name="methodNode">The method node.</param>
        /// <returns>
        ///   <c>true</c> if [is method return void] [the specified method node]; otherwise, <c>false</c>.
        /// </returns>
        public static Boolean IsMethodReturnVoid(this MethodDeclarationSyntax methodNode)
        {
            var predefinedTypeSyntax = methodNode.ReturnType as PredefinedTypeSyntax;

            // return type is void
            return predefinedTypeSyntax != null 
                && predefinedTypeSyntax.Keyword.Kind == SyntaxKind.VoidKeyword;
        }

        public static Method AsInterfaceMethod(this Method @this, Interface parent = null)
        {
            return new InterfaceMethod(
                @this.GetSyntaxNode(), parent);
        }
    }
}